package com.levi.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author shentong
 * @since 2022/1/16 5:29 PM
 * runafterBoth只要前面任务执行完之后就执行，不许需要前面任务的执行结果，且没有返回值
 */
public class RunafterBothDemo {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        CompletableFuture<String> future1 = CompletableFuture.supplyAsync(() -> "hello", executorService);

        CompletableFuture<String> future2 = CompletableFuture.supplyAsync(() -> "world", executorService);

        CompletableFuture<Void> future3 = future1.runAfterBothAsync(future2,()->{
            System.out.println("只要前面任务执行完之后，我就执行，切不需要前面任务的执行结果,且没有返回值");
        }, executorService);
//        try {
//            System.out.println("执行结果是：>>"+future3.get());
//        } catch (InterruptedException | ExecutionException e) {
//            e.printStackTrace();
//        }
        System.out.println("Main end~~");
        executorService.shutdown();
    }
}
